package main

import (
	"io"
	"net/http"
	"net/rpc"
	"net/rpc/jsonrpc"
	. "test-go/src/rpc/hello_rpc"
)

/*
POST
http://127.0.0.1:9999/jsonrpc
{"method":"x/xx/HelloService.Hello", "params":["jasper"]}
*/
func main() {
	RegisterHelloService(new(HelloService))
	http.HandleFunc("/jsonrpc", func(w http.ResponseWriter, r *http.Request) {
		var conn io.ReadWriteCloser = struct {
			io.ReadCloser
			io.Writer
		}{
			ReadCloser: r.Body,
			Writer:     w,
		}

		rpc.ServeRequest(jsonrpc.NewServerCodec(conn))
	})

	http.ListenAndServe(ADDRESS, nil)
}
